﻿using System;
using System.Collections.Generic;
using System.Text;
using SampleImageGenerator.Rendering;
using LibNoise;
using System.Drawing;

namespace SampleImageGenerator.Factories
{
	internal class PaletteFactory
	{
		private Int32 salt = 0xcafe;

		public IPalette GetPalette(Int32 seed)
		{
			Random random = new Random(seed ^ salt);

			LinearPalette linear0 = new LinearPalette();
			linear0.Name = "Linear greyscale"; 

			LinearPalette linear1 = new LinearPalette();
			linear1.ColourPoints = new LinearPalette.ColourPoint[] {
				new LinearPalette.ColourPoint(-3, Color.DarkBlue),
				new LinearPalette.ColourPoint(0, Color.SpringGreen),
				new LinearPalette.ColourPoint(3, Color.Yellow)
			};
			linear1.Name = "Linear blue, green, yellow";

			LinearPalette linear2 = new LinearPalette();
			linear2.ColourPoints = new LinearPalette.ColourPoint[] {
				new LinearPalette.ColourPoint(-3, Color.Black),
				new LinearPalette.ColourPoint(-1.5, Color.MidnightBlue),
				new LinearPalette.ColourPoint(0, Color.YellowGreen),
				new LinearPalette.ColourPoint(1.5, Color.Green),
				new LinearPalette.ColourPoint(3, Color.GhostWhite)
			};
			linear2.Name = "Linear black, blue, yellow, green, white";

			Int32 billowSeed;
			FastBillow paletteModule;

			billowSeed = random.Next();
			paletteModule = new FastBillow(billowSeed);
			paletteModule.Frequency = 0.8;
			paletteModule.OctaveCount = 1;
			ModulePalette module1 = new ModulePalette(paletteModule);
			module1.Name = String.Format("Billow {0}", billowSeed);

			billowSeed = random.Next();
			paletteModule = new FastBillow(billowSeed);
			paletteModule.Frequency = 2.5;
			paletteModule.OctaveCount = 1;
			ModulePalette module2 = new ModulePalette(paletteModule);
			module2.Name = String.Format("Billow {0}", billowSeed);


			IPalette[] palettes = new IPalette[] {
				linear0,
				linear1,
				linear2,
				module1,
				module2
			};

			Int32 index = random.Next(0, palettes.Length);
			IPalette palette = palettes[index];

			return palette; 
		}
	}
}
